<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <base href="<%=basePath%>">
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="<%=basePath %>leyuiyc/css/font.css">
    <link rel="stylesheet" href="<%=basePath %>leyuiyc/css/xadmin.css">
    <script type="text/javascript" src="<%=basePath %>leyuiyc/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=basePath %>leyuiyc/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>修改打包商品</legend>
</fieldset>
<form class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">打包商品名称</label>
            <div class="layui-input-inline">
                <input type="text" name="baleGoodName" lay-verify="required" value="${BaleGoods.baleGoodName }"
                       lay-reqtext="商品名称是必填项，岂能为空？" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">打包商品价格</label>
            <div class="layui-input-inline">
                <input type="text" name="baleGoodPrice" placeholder="请输入两位小数" lay-verify="baleGoodPrice"
                       value="${BaleGoods.baleGoodPrice }" lay-reqtext="商品价格必填项，岂能为空？" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">打包商品数量</label>
            <div class="layui-input-inline">
                <input type="text" name="baleAmount" placeholder="请输入正整数" lay-verify="baleAmount"
                       value="${BaleGoods.baleAmount }" lay-reqtext="商品数量是必填项，岂能为空？" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">打包商品预售数量</label>
            <div class="layui-input-inline">
                <input type="text" name="balePresaleNum" placeholder="请输入正整数" lay-verify="balePresaleNum"
                       value="${BaleGoods.balePresaleNum }" lay-reqtext="打包商品预售数量是必填项，岂能为空？" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">打包商品有效期</label>
            <div class="layui-input-block">
                <input class="layui-input" name="baleGoodValidity" id="newdate" lay-verify="date" value="${date }"
                       placeholder="yyyy-MM-dd" autocomplete="off">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">打包商品对应公共商品id</label>
            <div class="layui-input-inline">
                <input type="text" name="commonGoodsId" placeholder="请输入正整数" lay-verify="commonGoodsId"
                       value="${BaleGoods.commonGoodsId }" lay-reqtext="打包商品对应公共商品id是必填项，岂能为空？" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">打包商品对应的公共商品的价格</label>
            <div class="layui-input-inline">
                <input type="text" name="baleGoodsPrice" placeholder="请输入两位小数" lay-verify="baleGoodsPrice"
                       value="${BaleGoods.baleGoodsPrice }" lay-reqtext="打包商品对应的公共商品的价格是必填项，岂能为空？" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">打包商品状态</label>
            <div class="layui-input-inline">
                <select name="status" lay-verify="required" lay-search="">
                    <option value="">请选择</option>
                    <option value="0" <c:if test="${BaleGoods.status eq '0'}"> selected </c:if>>下架</option>
                    <option value="1" <c:if test="${BaleGoods.status eq '1'}"> selected </c:if>>上架</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">赠送积分</label>
            <div class="layui-input-inline">
                <input type="text" name="awardedIntegral" placeholder="请输入正整数" value="${BaleGoods.awardedIntegral }"
                       lay-verify="awardedIntegral" lay-reqtext="赠送积分是必填项，岂能为空？" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">是否可积分兑换</label>
            <div class="layui-input-inline">
                <select name="integralBuy" lay-verify="required" lay-search="">
                    <option value="">请选择</option>
                    <option value="0" <c:if test="${BaleGoods.integralBuy eq '0'}"> selected </c:if>>不能</option>
                    <option value="1" <c:if test="${BaleGoods.integralBuy eq '1'}"> selected </c:if>>能</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">兑换所需积分</label>
            <div class="layui-input-inline">
                <input type="text" name="goodsExchIntegral" placeholder="请输入正整数" lay-verify="goodsExchIntegral"
                       value="${BaleGoods.goodsExchIntegral }" lay-reqtext="必填项，岂能为空？" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">运费</label>
            <div class="layui-input-inline">
                <input type="text" name="shippingFee" placeholder="请输入两位小数" value="${BaleGoods.shippingFee }"
                       lay-verify="shippingFee" lay-reqtext="运费是必填项，岂能为空？" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">是否可以退货</label>
            <div class="layui-input-inline">
                <select name="goodsRefund" lay-verify="required" lay-search="">
                    <option value="">请选择</option>
                    <option value="0" <c:if test="${BaleGoods.goodsRefund eq '0'}"> selected </c:if>>不能</option>
                    <option value="1" <c:if test="${BaleGoods.goodsRefund eq '1'}"> selected </c:if>>能</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">退货费用</label>
            <div class="layui-input-inline">
                <input type="text" name="returnFee" placeholder="请输入两位小数" lay-verify="returnFee"
                       value="${BaleGoods.returnFee }" value="0.00" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">创建人ID</label>
            <div class="layui-input-inline">

                <input type="text" name="createUserId" placeholder="请输入正整数" lay-verify="createUserId"
                       value="${userinfo.userId }" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">创建人姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="createUserName" lay-verify="required" value="${userinfo.userName }"
                       class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <input class="fileupload-input" id="gcPicpath" type="hidden" name="picpath" value="${BaleGoods.picpath }"/>
        <input class="fileupload-input" id="thumbPicpath" type="hidden" name="thumbPicpath" value="${BaleGoods.picpath }"/>
    </div>
    <div class="layui-form-item">
        <input class="fileupload-input" id="baleGoodsId" type="hidden" name="baleGoodsId"
               value="${BaleGoods.baleGoodsId }"/>
    </div>
    <div class="layui-form-item">
        <label for="L_repass" class="layui-form-label"></label>
        &emsp;&emsp;&emsp;
        <button class="layui-btn" lay-filter="add" lay-submit="">保 &emsp;&emsp; 存</button>
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; &emsp;&emsp;&emsp;
        &emsp;&emsp;
        <a href="BaleGoods/goBaleGoods.do">
            <button type="button" class="layui-btn layui-btn-warm">返 &emsp;&emsp; 回</button>
        </a></div>
</form>
<div class="layui-form-item" style="position: absolute;top: 150px;left: 850px;">
    <button class="layui-btn layui-btn-danger layui-btn-radius" id="editimg1">如果需要修改图片请点击这里上传图片</button>
</div>
<div style="height:400px;width:400px;position: absolute;top: 250px;left: 850px;">
    <img alt="" id="img" src="${fileServerUrl}${BaleGoods.picpath }">
</div>

<script>
    layui.use(['form', 'layedit', 'laydate', "jquery"], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , $ = layui.jquery;
        //日期
        laydate.render({
            elem: '#newdate'
            , trigger: 'click'
        });
        //监听提交
        form.on('submit(add)', function (data) {
            $.ajax({
                url: "BaleGoods/modifyBaleGoods.do",
                method: "post",
                data: JSON.stringify(data.field),
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (data) {
                    console.log(data)
                    layer.msg('修改成功！',
                        {icon: 6},
                        function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                }
            })
            return false;
        });
        //自定义验证规则
        form.verify({
            goodsExchIntegral: [
                /^\d+$/
                , '请输入正确格式的数字且不能带空格'
            ]
            , createUserId: [
                /^\d+$/
                , '请输入正确格式的数字且不能带空格'
            ]
            , commonGoodsId: [
                /^\d+$/
                , '请输入正确格式的数字且不能带空格'
            ]
            , baleAmount: [
                /^\d+$/
                , '请输入正确格式的数字且不能带空格'
            ]
            , shippingFee: [
                /^[0-9]+(\.[0-9]{2})?$/
                , '请输入正确格式的数字且不能带空格'
            ]
            , baleGoodPrice: [
                /^[0-9]+(\.[0-9]{2})?$/
                , '请输入正确格式的数字且不能带空格'
            ]
            , baleGoodsPrice: [
                /^[0-9]+(\.[0-9]{2})?$/
                , '请输入正确格式的数字且不能带空格'
            ]
            , returnFee: [
                /^[0-9]+(\.[0-9]{2})?$/
                , '请输入正确格式的数字且不能带空格'
            ]
            , awardedIntegral: [
                /^\d+$/
                , '请输入正确格式的数字且不能带空格'
            ]
            , balePresaleNum: [
                /^\d+$/
                , '请输入正确格式的数字且不能带空格'
            ]

            , content: function (value) {
                layedit.sync(editIndex);
            }
        });
    });
</script>
<script type="text/javascript">
    layui.config({
        base: 'http://localhost:8091/tvmallbs/layui/lay/mymodules/'
    }).use(["element", "layer", 'croppers', "form", "table", "jquery"], function () {
        var elem = layui.element;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var upload = layui.upload;
        var croppers = layui.croppers;
        var $ = layui.jquery;
        croppers.render({
            elem: '#editimg1'
            , saveW: 350     //保存宽度
            , saveH: 350
            , mark: 1 / 1    //选取比例
            , area: '900px'  //弹窗宽度
            , url: "BaleGoods/UploadPictures.do"  //图片上传接口返回和（layui 的upload 模块）返回的JOSN一样
            , done: function (data) { //上传完毕回调
                console.log(data);
                $("#img").attr('src', data);
                $("#gcPicpath").attr('value', data);

            }
        });
        //var id = ${selectGoodsClassDetil.gcId};
        //console.log(id);
        //layui.common.init();

    });
</script>

</body>

</html>
